﻿using NationalD3.Domain.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NationalD3.Domain.ValueObjects
{
    /// <summary>
    /// Address值对象
    /// </summary>
    public class Address : ValueObject<Address>
    {
        /// <summary>
        /// 省份
        /// </summary>
        public string Province { get; private set; }

        /// <summary>
        /// 城市
        /// </summary>
        public string City { get; private set; }

        /// <summary>
        /// 区县
        /// </summary>
        public string County { get; private set; }

        /// <summary>
        /// 街道
        /// </summary>
        public string Street { get; private set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public Address() { }
        public Address(string province, string city,
            string county, string street)
        {
            this.Province = province;
            this.City = city;
            this.County = county;
            this.Street = street;
        }

        /// <summary>
        /// 判断两个值对象是否相同
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        protected override bool EqualsCore(Address other)
        {
            return this.Province.Equals(other.Province) &&
                   this.City.Equals(other.City) &&
                   this.County.Equals(other.County) &&
                   this.Street.Equals(other.Street);
        }

        /// <summary>
        /// 获取哈希值
        /// </summary>
        /// <returns></returns>
        protected override int GetHashCodeCore()
        {
            const int hashIndex = 307;
            var result = Province != null ? Province.GetHashCode() : 0;
            result = (result * hashIndex) ^ (City != null ? City.GetHashCode() : 0);
            result = (result * hashIndex) ^ (County != null ? County.GetHashCode() : 0);
            result = (result * hashIndex) ^ (Street != null ? Street.GetHashCode() : 0);

            return result;
        }
    }
}
